<!doctype html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登陆</title>
    <link rel="stylesheet" type="text/css" href="css/stylesLogin.css">
    <script src="js/md5.js"></script>
</head>

<body>
    <div class="htmleaf-container">
        <div class="wrapper">
            <div class="container">
                <div id="k">
                    <h1>金榜系统</h1>

                    <form class="form" method="POST">
                        <input id="account" type="text" placeholder="账号" value="铁柱">
                        <input id="pwd" type="password" placeholder="密码" value="123456">
                        <button type="submit" id="login-button" onclick="login()">登录</button>
                    </form>
                </div>

            </div>
        </div>
    </div>

    <script src="js/jquery-3.4.1.min.js" type="text/javascript"></script>
    <script>
        // var domin = "http://localhost:8081/jinbang/";
        var domin = "http://11pm.top:8081/jinbang/";
        
        jQuery.support.cors = true;
        $('#login-button').click(function(event) {
            event.preventDefault();
            $('form').fadeOut(500);
            $('.wrapper').addClass('form-success');
        });

        function login() {
            let account = $("#account").val().toString();
            let pwd = $("#pwd").val().toString();
            pwd = pwd.MD5(32);
            let dataReq = {
                "name": account,
                "pwd": pwd
            };
            // console.log(data);
            jQuery.support.cors = true;
            // 登录
            $.ajax({
                type: "POST",
                url: domin + "home",
                dataType: 'JSON',
                data: JSON.stringify(dataReq),
                contentType : "application/json",
                xhrFields: {
                    withCredentials: true
                },
                success: function(data) {
                    // console.log(data);
                    if (data.success == "Login successful!") {
                        window.localStorage.setItem("name", dataReq.name);
                        window.location.href = "home.html";
                    }
                },
                error: function(data){
                    console.log("ajax 失败回调");
                    // window.location.href='index.html';
                }
            });
        }
    </script>


</body>

</html>